﻿using GalaSoft.MvvmLight;
using WebberCross.Obelisk.MvvmLightDemo.Navigation;

namespace WebberCross.Obelisk.MvvmLightDemo.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class ExampleViewModel : TombstonePersistentBase
    {
        private MessageReceiver<ExampleInitMessage> _receiver = null;
        private string _messageText = null;

        public string ApplicationTitle
        {
            get { return "OBELISK MVVM LIGHT"; }
        }

        public string PageName
        {
            get { return "Navigation Example"; }
        }

        [Persist]
        public string MessageText
        {
            get { return this._messageText; }
            set
            {
                if (this._messageText != value)
                {
                    this._messageText = value;
                    base.RaisePropertyChanged("MessageText");
                }
            }
        }

        /// <summary>
        /// Initializes a new instance of the ExampleViewModel class.
        /// </summary>
        public ExampleViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
            }
            else
            {
                // Code runs "for real": Connect to service, etc...

                // Attach receiver and set to ask for init messages on instantiation
                this._receiver = new MessageReceiver<ExampleInitMessage>((message) =>
                  {
                      this.MessageText = message.Value;
                  }, true);
            }
        }

        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}
    }
}